
#include "DP_Param.h"
#include "APP_Main.h"
#include "wifi.h"


uint16_t DP_Count = 0; //Tick 10ms
uint16_t DP_Delay = 0; //Tick 10ms
uint8_t DP_Reset = 0;


uint8_t DP_Param_Switch(void)
{
    uint8_t ret = 0;
    static uint16_t temp = 0xffff; 

    if(DP_Reset > 0) temp = 0xffff;
    if(temp != UI_System.Grill_state)
    { 
        temp = UI_System.Grill_state;
        ret = mcu_dp_bool_update(DPID_SWITCH, (temp != State_Grill_Misfire)?1:0); //BOOL型数据上报;
    }
    return ret;
}
uint8_t DP_Param_RTDTempSetting(void)
{
    uint8_t ret = 0;
    static uint16_t temp = 0xffff; 
    uint8_t param = 0;

    if(DP_Reset > 0) temp = 0xffff;
    if(temp != UI_System.RTD.Settings)
    { 
        temp = UI_System.RTD.Settings;
        ret = mcu_dp_value_update(DPID_COOK_TEMPERATURE, temp);
    }
    return ret;
}
uint8_t DP_Param_RTDTemp(void)
{
    uint8_t ret = 0;
    static uint16_t temp = 0xffff; 
    uint8_t param = 0;

    if(DP_Reset > 0) temp = 0xffff;
    if(temp != UI_System.RTD.Actual)
    { 
        temp = UI_System.RTD.Actual;
        ret = mcu_dp_value_update(DPID_TEMP_CURRENT, temp);
    }
    return ret;
}

void DP_Param_Init(void)
{
    
}
void DP_Param_Main(void)
{
    static uint16_t count = 0;
    uint8_t temp = 0;
   
    if(OTA_IsActive() == true) return;
    if(DP_Delay == 0) DP_Delay = 1;
    if(DP_Delay < 20) return;
    DP_Delay = 0;

    temp = 0;
    for(; count < DP_Seq_Length;)
    {
        if(count == DP_Seq_Power) temp = DP_Param_Switch();
        else if(count == DP_Seq_RTDTempSetting) temp = DP_Param_RTDTempSetting();
        else if(count == DP_Seq_RTDTemp) temp = DP_Param_RTDTemp();
        count++;
        if(temp > 0) break;
    }
    if(count >= DP_Seq_Length)
    {
        count = 0; 
        DP_Reset = 0;
    }
}
//Tick 10ms
void DP_Param_Clock(void)
{
    if((DP_Delay > 0) && (DP_Delay < 0xffff)) DP_Delay++;
}
